﻿# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
cmake_minimum_required(VERSION 3.1.3)
project(MediaService VERSION 1.1)

#指定编译平台
set(CMAKE_SYSTEM_NAME Linux)
#set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_PROCESSOR x86)
set(CMAKE_BUILD_TYPE Release)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
    #arm
    message("CMAKE_SYSTEM_PROCESSOR " ${CMAKE_SYSTEM_PROCESSOR})

    set(TOOLCHAIN_PATH /opt/gcc-linaro-7.5.0)
    set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-linux-gnu-gcc)
    set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/bin/aarch64-linux-gnu-g++)
    set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg4.4.3_arm)

    #源文件
    file(GLOB MediaService_SRC_LIST ./*.cpp ./*.h)
    include_directories("./api/include")
    include_directories("./jsoncpp/include")
    include_directories("./redis++")
    include_directories("./redis++/future")
    include_directories("./redis++/no_tls")
    include_directories("./redis++/cxx11")
    include_directories("./hiredis")
    include_directories("./ffmpeg4.4.3/lib_arm/include")
    include_directories("./libyuv/lib_arm/include")
    add_executable(MediaService ${MediaService_SRC_LIST})

    #库设置
    link_directories("/usr/lib/aarch64-linux-gnu")
    set(LIBYUVPATH ${CMAKE_CURRENT_SOURCE_DIR}/libyuv/lib_arm/libyuv.a)
    target_link_libraries(MediaService ${LIBYUVPATH})
    target_link_libraries(MediaService -L${CMAKE_CURRENT_SOURCE_DIR}/common_lib/lib_arm -lmk_api)
    target_link_libraries(MediaService -L${CMAKE_CURRENT_SOURCE_DIR}/common_lib/lib_arm -ljsoncpp)
    target_link_libraries(MediaService -L${CMAKE_CURRENT_SOURCE_DIR}/common_lib/lib_arm -lhiredis)
    target_link_libraries(MediaService -L${CMAKE_CURRENT_SOURCE_DIR}/common_lib/lib_arm -lredis++)
    target_link_libraries(MediaService -L${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg4.4.3/lib_arm/lib -lavcodec -lavformat -lavutil -lswscale -lavdevice -lavfilter -lswresample -lpostproc -lx264
                                                                                         -lxcb -lv4l2 -lv4lconvert -lopus -ljpeg -lc -lm -lXau -lXdmcp -lbsd)
    target_link_libraries(MediaService -L/usr/lib/aarch64-linux-gnu -lpthread -lstdc++fs -lz -lpthread)

elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86")
    #linux x86
    message("CMAKE_SYSTEM_PROCESSOR " ${CMAKE_SYSTEM_PROCESSOR})

    #源文件
    file(GLOB MediaService_SRC_LIST ./*.cpp ./*.h)
    include_directories("./api/include")
    include_directories("./jsoncpp/include")
    include_directories("./redis++")
    include_directories("./redis++/future")
    include_directories("./redis++/no_tls")
    include_directories("./redis++/cxx11")
    include_directories("./hiredis")
    include_directories("./ffmpeg4.4.3/lib_linux/include")
    include_directories("./libyuv/lib_linux/include")
    add_executable(MediaService ${MediaService_SRC_LIST})

    set(LIBYUVPATH ${CMAKE_CURRENT_SOURCE_DIR}/libyuv/lib_linux/libyuv.a)
    target_link_libraries(MediaService ${LIBYUVPATH})
    target_link_libraries(MediaService -L${CMAKE_CURRENT_SOURCE_DIR}/common_lib/lib_linux -lmk_api)
    target_link_libraries(MediaService -L${CMAKE_CURRENT_SOURCE_DIR}/common_lib/lib_linux -ljsoncpp)
    target_link_libraries(MediaService -L${CMAKE_CURRENT_SOURCE_DIR}/common_lib/lib_linux -lhiredis)
    target_link_libraries(MediaService -L${CMAKE_CURRENT_SOURCE_DIR}/common_lib/lib_linux -lredis++)
    target_link_libraries(MediaService -L/usr/lib/x86_64-linux-gnu -lavcodec -lavformat -lavutil -lswscale -lavdevice -lavfilter -lswresample -lpostproc
                                                                                         -lxcb -ljpeg -lc -lm -lXau -lXdmcp)
    target_link_libraries(MediaService -L/usr/lib/x86_64-linux-gnu -lpthread -lstdc++fs -lz -lpthread)

else()
    # windows

endif()


